const express = require('express');
const login = require('./admin/login.js');
const product = require('./admin/product.js');

let router = express.Router()   //可使用express.Router 类创建模块化，可挂载的路由句柄

//自定义中间件，判断登录状态
router.use(function (req, res, next) {
    console.log(req.url )
    if (req.url == '/login' || req.url == '/login/dologin') {
        next()
    } else {
        if (req.session.useinfo && req.session.useinfo.usename != '') {
            next()
        } else {
            res.redirect('/admin/login')
        }
    }
})


//配置路由
router.use('/login',login);
router.use('/product',product);

module.exports = router;